﻿<template>
  <div class="projectQa-container" style="height:auto">
    <el-card >
      <p style="text-align: center;font-size: 26pt;">问卷调查</p>
      <el-card>
        <span style="font-size: 25pt;font-weight: 600;">1.项目业务背景</span>
        <div> 
        <label style="font-size:18pt">1.本项目的主要收货对象是下一级仓库、门店还是个人消费者？        </label>
         <p></p>
        <el-select v-model="state.selectlist" placeholder="请选择" >
          <el-option label='门店' value='option1'></el-option>
          
          <el-option label='门店' value='option1'></el-option>
          <el-option>个人消费者</el-option>
        </el-select>
      </div>
      <div>
        <label style="font-size:18pt">2.仓库业务流程的简单描述？</label>  
        <p></p> <el-input v-model="state.textarea1" type="textarea" style=""></el-input> 
      
      </div>
      </el-card> 
      <el-card>
        <span style="font-size: 25pt;font-weight: 600;">2.货物信息</span>
        <div> 
        <label style="font-size:18pt;margin-top: 50px;">1.货物的种类数量及主要分类规则（如按SKU、品类等）是什么？      </label>
         <p></p>
        <el-select size="medium" v-model="state.selectvalues2"  placeholder="请选择" >
      <el-option
      v-for="item in state.selectlist2"
      :key="item.value"
      :label="item.key"
      :value="item.value" >
    </el-option>
        </el-select>
<br/>
        <label style="font-size:18pt">2.货物的最大尺寸（长、宽、高）是多少？     </label>
         <p></p>
        <el-select size="medium" v-model="state.selectvalues3"  placeholder="请选择" >
          <el-option
      v-for="item in state.selectlist3"
      :key="item.value"
      :label="item.key"
      :value="item.value" >
    </el-option>
        </el-select>
        <br/>
        <label style="font-size:18pt;margin-top: 20px;">3.货物的重量范围（单位：公斤）是多少？    </label>
         <p></p>
        <el-select size="medium" v-model="state.selectvalues4"  placeholder="请选择" >
          <el-option
      v-for="item in state.selectlist4"
      :key="item.value"
      :label="item.key"
      :value="item.value" >
    </el-option>
        </el-select>
        <br/>
        <label style="font-size:18pt;margin-top: 20px;">4.日均分拣量（单位：件/天）是多少？   </label>
         <p></p>
        <el-select size="medium" v-model="state.selectvalues5"  placeholder="请选择" >
      
          <el-option
      v-for="item in state.selectlist5"
      :key="item.value"
      :label="item.key"
      :value="item.value" >
    </el-option>
        </el-select>
        <br/>
        <label style="font-size:18pt;margin-top: 20px;">5.高峰期分拣量是多少？   </label>
         <p></p>
        <el-select size="medium" v-model="state.selectvalues6"   placeholder="请选择" >
          <el-option
      v-for="item in state.selectlist6"
      :key="item.value"
      :label="item.key"
      :value="item.value" >
          </el-option>
        </el-select>
        <br/>
        <label style="font-size:18pt">6.日内的分拣量是否有波动要求？</label>  
        <p></p> <el-input v-model="state.textarea2" type="textarea" style=""></el-input> 
      



      </div>
      </el-card>
      <el-card>
        <span style="font-size: 25pt;font-weight: 600;">3.相关配套</span>
        <div> 
        <label style="font-size:18pt">1.当前分拣作业方式、主要痛点、需要提升点是什么？        </label>
         <p>1.现有货物的识别方式</p>
         <p></p> <el-input v-model="state.textarea3" type="textarea" style=""></el-input> 
          <br/>
          <label style="font-size:18pt">2.每天作业时长？几班倒</label>
          <p></p>  <el-select size="medium" v-model="state.selectvalues7"   placeholder="请选择" >
            <el-option
      v-for="item in state.selectlist7"
      :key="item.value"
      :label="item.key"
      :value="item.value" >
    </el-option>
        </el-select>
        <br/>
        <label style="font-size:18pt">3.分拣区的长*宽尺寸</label>
        <p></p> <el-input v-model="state.textarea4" type="textarea" style=""></el-input> 
        <br/>
        <label style="font-size:18pt">4.当前人工分拣的人员数量是多少？</label>
        <p></p> <el-input v-model="state.textarea5" type="textarea" style=""></el-input> 

      </div>
      </el-card> 
  
			<template #footer > 
     <div style="text-align: right;">
        <el-button  >{{ $t('message.pageConfiguration.cancel') }}</el-button>
					<el-button type="primary"  @click="savqa" >{{ $t('message.pageConfiguration.save') }}</el-button>
					<el-button type="primary"  @click="opendetail"  >生成方案</el-button> 

        </div>
     </template>
    </el-card>
    
    <Detail ref="DetailRef"  />
  </div>
</template>

<script lang="ts" setup="" name="projectQa">
import { onMounted, onUnmounted, reactive, ref, defineAsyncComponent, nextTick, watch } from 'vue';
import { ElMessageBox, ElMessage } from 'element-plus';
import mittBus from '/@/utils/mitt';
import editDialog from '/@/views/main/projectQa/component/editDialog.vue'
import { getDictDataItem as di, getDictDataListToSelect as dl } from '/@/utils/dict-utils';
import { pageProjectQa, deleteProjectQa, batchDeleteProjectQa, importProjectQa, downLoadProjectQa } from '/@/api/main/projectQa';
import { getAPI } from '/@/utils/axios-utils';
import { SysEnumApi } from '/@/api-services/api';
import commonFunction from '/@/utils/commonFunction';

import Detail from '/@/views/main/projectResult/component/Detail.vue'
import { auth } from '/@/utils/authFunction'
import { useI18n } from 'vue-i18n';
import router from "/@/router";
const { t, locale } = useI18n();
const { downFile } = commonFunction();
// 引入组件
const Table = defineAsyncComponent(() => import('/@/components/table/index.vue'));
const TableSearch = defineAsyncComponent(() => import('/@/components/table/search.vue'));

const uploaddialog = defineAsyncComponent(() => import('/@/components/table/uploaddialog.vue'));

const uploaddialogRef = ref();
const loading = ref();

const DetailRef = ref();
// 页面加载时
onMounted(async () => {
});
const savqa=()=>{
  
  router.push({ path: '/project/projectResult' })
};
const savepproandqa=()=>{
  console.log('route to projectResult')
  
  router.push({ path: '/project/projectResult/component/Detail' })
}
const tableRef = ref<RefType>();
const editDialogRef = ref();
const state = reactive({
  editprojectQaTitle: '',
  selectlist: [{key:'门店',value:'1'},{key:'个人消费者',value:'2'}] as EmptyObjectType[],
  selectlist2: [{key:'鞋',value:'1'},{key:'服',value:'2'},{key:'配',value:'3'}] as EmptyObjectType[],
  selectlist3: [{key:'鞋子：41*34*15',value:'1'},{key:'衣服：80*50*18',value:'2'},{key:'配件：60*40*17',value:'3'}],
  selectlist4: [{key:'配件：0.02-1.36KG',value:'1'},{key:'衣服：0.3-1.6 KG',value:'2'},{key:'鞋子：0.36-1.8KG',value:'3'}] as EmptyObjectType[],
  selectlist5: [{key:'整箱：1000件',value:'1'},{key:'零散1000件',value:'2'}] as EmptyObjectType[],
  selectlist6: [{key:'整箱：19200件',value:'1'},{key:'零拣：76800件',value:'2'}] as EmptyObjectType[],
  selectlist7: [{key:'日常8H',value:'1'},{key:'高峰20H（白夜班）',value:'2'}] as EmptyObjectType[],
 
selectvalues2:"",
selectvalues3:"",
selectvalues4:"",
selectvalues5:"",
selectvalues6:"",
selectvalues7:"",

textarea1:"",
textarea2:"",
textarea3:"",
textarea4:"",
textarea5:"",
  groupList: [] as Array<String>
  ,
});
const opendetail = ( ) => {
  let row={
    "id": 19633689384773,
    "projectNo": "P1",
    "gCode": "GT1",
    "deviceList": "xx",
    "vmPathNew": "xx",
    "cadPathNew": "xx",
    "efficiency": "2000pcs/H",
    "robotModel": "M2",
    "robotQty": "200",
    "blanketMode": "I",
    "binType": "无滑槽",
    "binSize": "40*40*50",
    "chargeQty": 100,
    "binQty": 100,
    "packQty": 50,
    "length": 1000,
    "width": 300,
    "robotCode": "M1",
    "blanketCode": "A1",
    "binTypeCode": "B1",
    "chargeCode": "C1",
    "totalPrice": "100000",
    "createUserName": "超级管理员",
    "updateUserName": "超级管理员"
};
  DetailRef.value?.openDialog(row);
};
const tb = reactive<TableDemoState>
  ({
    tableData: {

      // 表头内容（必传，注意格式）
      columns: [
        { prop: 'qACode', width: 130, label: t('message.projectQa.qACode'), headerAlign: 'center', toolTip: true, sortable: 'custom', isCheck: true },
        { prop: 'qAName', width: 130, label: t('message.projectQa.qAName'), headerAlign: 'center', toolTip: true, sortable: 'custom', isCheck: true },
        { prop: 'qAIndex', width: 130, label: t('message.projectQa.qAIndex'), headerAlign: 'center', toolTip: true, sortable: 'custom', isCheck: true },
        { prop: 'qAContent', width: 130, label: t('message.projectQa.qAContent'), headerAlign: 'center', toolTip: true, sortable: 'custom', isCheck: true },
        { prop: 'gField', width: 130, label: t('message.projectQa.gField'), headerAlign: 'center', toolTip: true, sortable: 'custom', isCheck: true },
        { prop: 'inputValues', width: 130, label: t('message.projectQa.inputValues'), headerAlign: 'center', toolTip: true, sortable: 'custom', isCheck: true },
        { prop: 'newDVaule', width: 130, label: t('message.projectQa.newDVaule'), headerAlign: 'center', toolTip: true, sortable: 'custom', isCheck: true },
        { prop: 'createUserName', width: 130, label: t('message.projectQa.createUserName'), headerAlign: 'center', toolTip: true, sortable: 'custom', isCheck: true },
        { prop: 'updateUserName', width: 130, label: t('message.projectQa.updateUserName'), headerAlign: 'center', toolTip: true, sortable: 'custom', isCheck: true },
        { prop: 'action', width: 140, label: t('message.pageConfiguration.operate'), type: 'action', align: 'center', isCheck: true, fixed: 'right', hideCheck: true },
      ],
      // 配置项（必传）
      config: {
        isStripe: true, // 是否显示表格斑马纹
        isBorder: false, // 是否显示表格边框
        isSerialNo: false, // 是否显示表格序号
        isSelection: true, // 是否勾选表格多选
        showSelection: auth('projectQa:batchDelete'), //是否显示表格多选
        pageSize: 20, // 每页条数
        hideExport: false, //是否隐藏导出按钮
        exportFileName: 'projectQa', //导出报表的文件名，不填写取应用名称
      },
      // 搜索表单，动态生成（传空数组时，将不显示搜索，type有3种类型：input,date,select）
      search: [
        { label: t('message.projectQa.qACode'), prop: 'qACode', placeholder: t('message.projectQa.qACode'), required: false, type: 'input' },
        { label: t('message.projectQa.qAName'), prop: 'qAName', placeholder: t('message.projectQa.qAName'), required: false, type: 'input' },
        { label: t('message.projectQa.qAContent'), prop: 'qAContent', placeholder: t('message.projectQa.qAContent'), required: false, type: 'input' },
        { label: t('message.projectQa.gField'), prop: 'gField', placeholder: t('message.projectQa.gField'), required: false, type: 'input' },
        { label: t('message.projectQa.inputValues'), prop: 'inputValues', placeholder: t('message.projectQa.inputValues'), required: false, type: 'input' },
        { label: t('message.projectQa.newDVaule'), prop: 'newDVaule', placeholder: t('message.projectQa.newDVaule'), required: false, type: 'input' },
        { label: t('message.projectQa.createUserName'), prop: 'createUserName', placeholder: t('message.projectQa.createUserName'), required: false, type: 'input' },
        { label: t('message.projectQa.updateUserName'), prop: 'updateUserName', placeholder: t('message.projectQa.updateUserName'), required: false, type: 'input' },
      ],
      param: {},
      defaultSort: {
        prop: 'createTime',
        order: 'ascending',
      },
    },
  });
// 监听语言切换
watch(locale, async () => {
  // 更新表头和搜索表单的国际化文本
  tb.tableData.columns.forEach(column => {
    switch (column.prop) {
      case 'id':
        column.label = t('message.projectQa.id');
        break;
      case 'qACode':
        column.label = t('message.projectQa.qACode');
        break;
      case 'qAName':
        column.label = t('message.projectQa.qAName');
        break;
      case 'qAIndex':
        column.label = t('message.projectQa.qAIndex');
        break;
      case 'qAContent':
        column.label = t('message.projectQa.qAContent');
        break;
      case 'gField':
        column.label = t('message.projectQa.gField');
        break;
      case 'inputValues':
        column.label = t('message.projectQa.inputValues');
        break;
      case 'newDVaule':
        column.label = t('message.projectQa.newDVaule');
        break;
      case 'createUserName':
        column.label = t('message.projectQa.createUserName');
        break;
      case 'updateUserName':
        column.label = t('message.projectQa.updateUserName');
        break;
      case 'action':
        column.label = t('message.pageConfiguration.operate');
        break;
    }
  });

  // 更新搜索表单的国际化文本
  tb.tableData.search.forEach(searchItem => {
    switch (searchItem.prop) {
      case 'id':
        searchItem.label = t('message.projectQa.id');
        searchItem.placeholder = t('message.projectQa.id');
        break;
      case 'qACode':
        searchItem.label = t('message.projectQa.qACode');
        searchItem.placeholder = t('message.projectQa.qACode');
        break;
      case 'qAName':
        searchItem.label = t('message.projectQa.qAName');
        searchItem.placeholder = t('message.projectQa.qAName');
        break;
      case 'qAIndex':
        searchItem.label = t('message.projectQa.qAIndex');
        searchItem.placeholder = t('message.projectQa.qAIndex');
        break;
      case 'qAContent':
        searchItem.label = t('message.projectQa.qAContent');
        searchItem.placeholder = t('message.projectQa.qAContent');
        break;
      case 'gField':
        searchItem.label = t('message.projectQa.gField');
        searchItem.placeholder = t('message.projectQa.gField');
        break;
      case 'inputValues':
        searchItem.label = t('message.projectQa.inputValues');
        searchItem.placeholder = t('message.projectQa.inputValues');
        break;
      case 'newDVaule':
        searchItem.label = t('message.projectQa.newDVaule');
        searchItem.placeholder = t('message.projectQa.newDVaule');
        break;
      case 'createUserName':
        searchItem.label = t('message.projectQa.createUserName');
        searchItem.placeholder = t('message.projectQa.createUserName');
        break;
      case 'updateUserName':
        searchItem.label = t('message.projectQa.updateUserName');
        searchItem.placeholder = t('message.projectQa.updateUserName');
        break;
    }
  });

  // 等待下一次 DOM 更新循环完成后再进行表格刷新
  await nextTick();
  tableRef.value?.handleList(); // 刷新表格数据
});
const getData = async (param: any) => {

  loading.value = true;
  var res = await pageProjectQa(Object.assign(param));

  loading.value = false;
  return res.data;
};
const exportChangeData = (data: Array<EmptyObjectType>
) => {
  data.forEach((item) => {
    item.sysFlag = item.sysFlag == 1 ? t('message.projectQa.yes') : t('message.projectQa.no');
  });
  return data;
};
// 拖动显示列排序回调
const onSortHeader = (data: object[]) => {
  tb.tableData.columns = data;
};
// 搜索点击时表单回调
const onSearch = (data: EmptyObjectType) => {
  tb.tableData.param = Object.assign({}, tb.tableData.param, { ...data });
  nextTick(() => {
    tableRef.value.pageReset();
  });
};

const getGroupList = async () => {

};

//表格多选事件
const tableSelection = (data: EmptyObjectType[]) => {
  // console.log('表格多选事件', data)
  state.selectlist = data;
};

onMounted(async () => {
  getGroupList();
});

// 更新数据
const updateData = () => {
  tableRef.value.handleList();
  getGroupList();
};

// 打开新增页面
const openaddprojectQa = () => {
  state.editprojectQaTitle = t('message.projectQa.addprojectQa');
  editDialogRef.value?.openDialog({});
};

// 打开编辑页面
const openedit = (row: any) => {
  state.editprojectQaTitle = t('message.projectQa.editprojectQa');
  editDialogRef.value?.openDialog(row);
};

// 删除
const delConfig = (row: any) => {
  ElMessageBox.confirm(t('message.messages.confirmDel') + `：【${row[tb.tableData.columns[1].prop.toString()]}】?`, t('message.messages.hint'), {
    confirmButtonText: t('message.messages.confirm'),
    cancelButtonText: t('message.messages.cancel'),
    type: 'warning',
  })
    .then(async () => {
      await deleteProjectQa({ id: row.id });
      tableRef.value.handleList();
      ElMessage.success(t('message.messages.deleteSuccess'));
    })
    .catch(() => { });
};

//批量删除
const bacthDelete = () => {
  if (state.selectlist.length == 0) return false;
  ElMessageBox.confirm(t('message.messages.confirmBatchDel') + `【${state.selectlist[0].name}】${state.selectlist.length}` + t('message.messages.con'), t('message.messages.hint'), {
    confirmButtonText: t('message.messages.confirm'),
    cancelButtonText: t('message.messages.cancel'),
    type: 'warning',
  })
    .then(async () => {
      const ids = state.selectlist.map((item) => {
        return item.id;
      });
      var res = await batchDeleteProjectQa(ids);
      tableRef.value.pageReset();
      ElMessage.success(t('message.messages.deleteSuccess'));
    })
    .catch(() => { });



};
// 打开上传页面
const openUploadDialog = () => {
  uploaddialogRef.value.openUploadDialog();
};
const importData = async (param: any) => {
  var res = await importProjectQa(param);
  return res;
};

const downTemplete = async () => {
  var res = await downLoadProjectQa();
  downFile(res);
}     
</script>
